using System;
using System.Text;
using Function.SkillEditor.Runtime;
using SCore.Editor.WindowDraw;
using UnityEditor;
using UnityEngine;

namespace Function.SkillEditor.Editor
{
    public class SkillLimitClipDraw : ISkillClipDrawer
    {
        public override void OnInspector(Rect rect)
        {
            base.OnInspector(rect);
            var clip = _skillClip as SkillLimitClip;
            var bPointRect = new Rect(rect.x, GetInspectorHeight(rect), rect.width, 20);
            var maskName = Enum.GetNames(typeof(SkillLimitType));
            var lableWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = 30f;
            clip._skillLimit = EditorGUI.MaskField(
                bPointRect, new GUIContent("限制"), clip._skillLimit, maskName
            );
            EditorGUIUtility.labelWidth = lableWidth;
        }

        protected override void ClipNameGUI()
        {
            StringBuilder tip = new StringBuilder();
            tip.Append("L:");
            var clip = _skillClip as SkillLimitClip;
            var values = Enum.GetValues(typeof(SkillLimitType));
            foreach (SkillLimitType limitType in values)
            {
                if (clip.IsLimit(limitType))
                {
                    tip.Append(limitType.ToString() + " ");
                }
            }

            EditorGUI.LabelField(_rect, tip.ToString(),
                EditorDrawHelp.GetTextGUIStyle(10, TextAnchor.MiddleCenter,
                    EditorDrawHelp._black, FontStyle.Bold));
        }
    }

    [TrackDrawEditor(typeof(SkillLimitTrack), typeof(SkillLimitClipDraw))]
    public class SkillLimitTrackDraw : ISkillTrackDrawer<SkillLimitTrack>
    {
        public SkillLimitTrackDraw(SkillLimitTrack skillTrack, TrackRegisterAttribute trackRegister) : base(skillTrack,
            trackRegister)
        {
        }

        protected override void DrawGroup()
        {
            EditorGUI.LabelField(new Rect(_headRect.x + 10, _headRect.y, _headRect.width, _headRect.height), "Limit");
        }
    }
}